package com.kaili.basic.controller;

import com.kaili.basic.pojo.entity.MdmUserSafetyEntity;
import com.kaili.basic.pojo.vo.MdmUserSafetyVo;
import com.kaili.basic.service.IMdmUserSafetyService;
import com.kaili.basic.version.ApiVersion;
import com.kaili.common.aop.OperateLogAspect;
import com.kaili.common.aop.log.enums.FunctionName;
import com.kaili.common.aop.log.enums.OperateType;
import com.kaili.common.response.CommonStatus;
import com.kaili.common.response.RestStatus;
import com.kaili.common.util.LoginDetailUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Desc: 账号安全controller
 * @author: shenliqiang
 * @Time: 2019/7/26 19:09
 * @Copyright: © 2018 杭州凯立通信有限公司 版权所有
 * @Warning: 本内容仅限于公司内部传阅, 禁止外泄或用于其它商业目的
 */
@RestController
@ApiVersion(1)
@RequestMapping("/{api_version}")
@Api(tags = "账户安全管理", description = "账户安全管理相关API")
public class MdmUserSafetyController {

    @Autowired
    private IMdmUserSafetyService IMdmUserSafetyService;

    /**
     * @desc    新增账号安全--finish
     * @author   shenliqiang
     * @param
     * @return
     * @date     2019/7/24 14:19
     */
    @PostMapping(value = "/usersafety/addUserSafety")
    @ApiOperation(value = "新增账号安全",notes = "新增账号安全",httpMethod = "POST")
    @OperateLogAspect(functionName = FunctionName.userSafety,operateType = OperateType.ADD,key = "userId")
    public RestStatus addOnlineDevice(@RequestParam Long userId){
        MdmUserSafetyEntity entity = new MdmUserSafetyEntity();
        entity.setUserId(userId);
        entity.setCreateBy(LoginDetailUtils.getCurrentEmployeeId().intValue());
        this.IMdmUserSafetyService.addMdmUserSafety(entity);
        return CommonStatus.ADD_OK;
    }

    /**
     * @desc    更新账号安全--finish
     * @author   shenliqiang
     * @param
     * @return
     * @date     2019/7/24 14:22
     */
    @PutMapping(value = "/usersafety/updateUserSafety")
    @ApiOperation(value = "修改账号安全",notes = "修改账号安全")
    @OperateLogAspect(functionName = FunctionName.userSafety,operateType = OperateType.UPDATE,key = "userId")
    public RestStatus updateOnlineDevice(@RequestParam int isRemote,@RequestParam int isMpop){
        MdmUserSafetyEntity mdmUserSafetyEntity = new MdmUserSafetyEntity();
        mdmUserSafetyEntity.setIsRemote(isRemote);
        mdmUserSafetyEntity.setIsMpop(isMpop);
        mdmUserSafetyEntity.setModifyBy(LoginDetailUtils.getCurrentEmployeeId().intValue());
        IMdmUserSafetyService.updateMdmUserSafety(mdmUserSafetyEntity);
        return CommonStatus.UPDATE_OK;
    }

    /**
     * @desc 删除账号安全--finished
     * @author   shenliqiang
     * @param
     * @return
     * @date     2019/7/24 14:23
     */
    @DeleteMapping("/usersafety/deleteUserSafety")
    @ApiOperation(value = "删除账号安全", notes = "删除账号安全")
    @OperateLogAspect(functionName = FunctionName.userSafety,operateType = OperateType.DELETE,key = "userId")
    public RestStatus deleteOnlineDevices() {
        IMdmUserSafetyService.deleteMdmUserSafety(LoginDetailUtils.getCurrentEmployeeId().intValue());
        return CommonStatus.DELETE_OK;
    }

    /**
     * @Desc:  查询账号安全--finished
     * @author: shenliqiang
     * @Time: 2019/7/25 11:25
     * @param
     * @return com.kaili.basic.pojo.vo.MdmDeviceOnlineDetailVo
     */

    @GetMapping(value = "/usersafety/queryUserSafety")
    @ApiOperation(value = "根据id查询账号安全",notes = "根据id查询账号安全")
    @ResponseBody
    public MdmUserSafetyVo queryOnlineDeviceDetail() {
        return IMdmUserSafetyService.queryMdmUserSafety(LoginDetailUtils.getCurrentEmployeeId().intValue());
    }

}
